

import GameLogic as g

c = g.getCurrentController()

#Empt Object
o = c.owner

wUp = o.sensors["wheel_up"]
wDown = o.sensors["wheel_down"]
m = o.sensors["MouseMove"]
mr = o.sensors["MouseRight"]

#sensitivity
s = 0.006

#dx and dy are reference points, needed to calculate the direction of movement of the mouse.
o["dx"] = o["lastX"] - m.position[0]
o["dy"] = o["lastY"] - m.position[1]


#on update last mouse position
o["lastX"] = m.position[0]
o["lastY"] = m.position[1]


def main():
    cf = g.getCurrentScene().objects.get('camera_focus') #rename to camera target
    ct = g.getCurrentScene().objects.get('cam_target') #rename to camera rotator
    
    #this allows us to copy the position of the focus object but not its rotation
    ct.position = cf.position
    
    
    
    #on rotate en fonction du mouvement de la souris
    if mr.positive :
        
        ori = ct.worldOrientation.to_euler()
        
        #map y screen coordinate to x object axis
        ori.x -= o["dy"] * s
        #map x screen coordinate to z object axis
        ori.z += o["dx"] * s
        #set the new orientation
        ct.worldOrientation = ori
    
    
    #on translate en fonction de la wheel
    wheel_sensitivity = 0.6
    
    if wUp.positive :
        o.localPosition.y -= wheel_sensitivity
    if wDown.positive :
        o.localPosition.y += wheel_sensitivity


main()